package monster.com.cvh.fragment;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import monster.com.cvh.R;

/**
 * @author: 13580
 * @data: 2018/4/8
 * @function:提示信息填写完整DialogFragment
 */
public class InfoUnCompeledDialogFragment extends DialogFragment {
    public static final String TIPS_INFO = "tips_info";
    private String mTipsInfo;

    public static InfoUnCompeledDialogFragment getInstance(String tipsInfo) {
        Bundle args = new Bundle();
        args.putString(TIPS_INFO, tipsInfo);
        InfoUnCompeledDialogFragment fragment = new InfoUnCompeledDialogFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle args = getArguments();
        if (args != null) {
            mTipsInfo = args.getString(TIPS_INFO);
        }
    }

    public Dialog onCreateDialog(Bundle savedInstanceState) {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_fragment_info_tips, null);
        TextView tvTipsInfo = (TextView) view.findViewById(R.id.tv_dialog_fragment_info_tips);
        if (mTipsInfo != null) {
            tvTipsInfo.setText(mTipsInfo);
        }
        Dialog dialog = new Dialog(getActivity());
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(view);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.gravity = Gravity.CENTER;
        attributes.width = WindowManager.LayoutParams.MATCH_PARENT;
        attributes.height = WindowManager.LayoutParams.WRAP_CONTENT;
        attributes.dimAmount = 0.3f;
        window.setAttributes(attributes);
        return dialog;
    }
}
